package com.design.observer;

import java.util.ArrayList;

/**
 * @author leali
 * @title: AllyControlCenter
 * @projectName design
 * @description: 战队控制中心类：目标类
 * @date 2022/1/3 20:34
 */
public abstract class AllyControlCenter {
    protected String allyName;
    protected ArrayList<Observer> players = new ArrayList<Observer>();

    public void setAllyName(String allyName) {
        this.allyName = allyName;
    }

    public String getAllyName() {
        return this.allyName;
    }

    /**
     * 注册方法
     * @param obs 成员
     */
    public void join(Observer obs) {
        System.out.println(obs.getName() + "加入" + this.allyName + "战队！");
        players.add(obs);
    }

    /**
     * 注销方法
     * @param obs 成员
     */
    public void quit(Observer obs) {
        System.out.println(obs.getName() + "退出" + this.allyName + "战队！");
        players.remove(obs);
    }

    /**
     * 声明抽象通知方法
     * @param name 战队名称
     */
    public abstract void notifyObserver(String name);
}
